import sys

import httplib2
import simplejson

from jsonstore.entries import EntryManager

h = httplib2.Http(".cache")
h.add_credentials('roberto', 'mozart')

em = EntryManager("dbm://entries")

for i in range(int(sys.argv[1])):
    url = "http://taoetc.org/%d" % i
    resp, content = h.request(url, "GET", headers={'content-type': 'application/json'})
    if resp['status'] != '404':
        entry = simplejson.loads(content)
        entry['id'] = entry['id'][len("http://taoetc.org/"):]
        em.create_entry(entry)
